<!--Copyright (C) Kherty.  All rights reserved.-->
<ResourceDictionary x:Class="OpenLS.Spreadsheet.UI.WorksheetPaneCellResources"
                    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:ssui="clr-namespace:OpenLS.Spreadsheet.UI"
                    xmlns:ss="http://schemas.Kherty.com/office/2007/spreadsheet"
                    xmlns:omedia="http://schemas.Kherty.com/office/2007/media"
                    xmlns:chartui="http://schemas.Kherty.com/office/2007/chart"
                    xmlns:drawing2="clr-namespace:OpenLS.Drawing.UI;assembly=OpenLS.Drawing.UI"
                    xmlns:Internals="clr-namespace:OpenLS.Spreadsheet.UI.Internals">
  <ResourceDictionary.MergedDictionaries>
    <ssui:CellResources />
    <ssui:WorksheetDrawingResources />
    <ssui:TableResources />
    <ssui:FilterColumnResources />
    <Internals:EditedCellResources />
    <Internals:FormulaReferenceResources />
    <Internals:CommentContainerResources></Internals:CommentContainerResources>
    <chartui:ChartResources />
    <ssui:RangeResources />
  </ResourceDictionary.MergedDictionaries>
  <DataTemplate DataType="{x:Type ss:WorksheetPane}" x:Key="paneCells">
    <Grid Name="m" Cursor="{x:Static omedia:OfficeCursors.DefaultCell}"
          ssui:SpreadsheetElement.WorksheetPane="{Binding}" ssui:SpreadsheetElement.WorksheetFragment="{Binding}"
          MouseWheel="onMouseWheel" Internals:FocusElement.FocusRoot="{Binding ElementName=EditingLayer}" Loaded="mainGridLoaded">
      <Grid Name="grid4">
        <Grid.Background>
          <ImageBrush x:Name="imageBrush" TileMode="Tile" Stretch="None"
                      ImageSource="{Binding Path=Worksheet.Background}" Viewport="{Binding Path=Worksheet.BackgroundViewport}"
                      ViewportUnits="Absolute" />
        </Grid.Background>
      </Grid>
      <ssui:GridLineControl WorksheetFragment="{Binding}"
                            LineBrush="{DynamicResource {x:Static ssui:SpreadsheetBrushes.GridLineBrushKey}}" />
      <ItemsControl Name="forTableBackgrounds" ItemsSource="{Binding Worksheet.Tables}"
                    ItemTemplate="{StaticResource tableBackground}" ItemContainerStyle="{StaticResource tableBackgroundContainerStyle}">
        <ItemsControl.ItemsPanel>
          <ItemsPanelTemplate>
            <ssui:WorksheetGrid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Focusable="False"
                                x:Name="tablePanel" Columns="{Binding Path=Worksheet.Columns}" Rows="{Binding Path=Worksheet.Rows}"
                                Top="{Binding Path=Top, Mode=TwoWay}" Left="{Binding Path=Left, Mode=TwoWay}" ClipToBounds="True" />
          </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>
      </ItemsControl>

      <Internals:CellBackgroundControl WorksheetPane="{Binding}" Focusable="False"
                                       ColorScheme="{Binding RelativeSource={RelativeSource Self}, Path=(drawing2:DrawingElement.ColorScheme)}" />
      <Internals:CellSparkLineControl WorksheetPane="{Binding}" Focusable="False"
                                      ColorScheme="{Binding RelativeSource={RelativeSource Self}, Path=(drawing2:DrawingElement.ColorScheme)}" />
      <ssui:SelectionAndActiveControl
Background="{DynamicResource {x:Static ssui:SpreadsheetBrushes.SelectionBackgroundKey}}"
Columns="{Binding Path=Worksheet.Columns}" Rows="{Binding Path=Worksheet.Rows}" Top="{Binding Path=Top}"
Left="{Binding Path=Left}" ActiveColumn="{Binding Path=Worksheet.ActiveCell.Column.Index}"
ActiveRow="{Binding Path=Worksheet.ActiveCell.Row.Index}"
ActiveColumnSpan="{Binding Path=Worksheet.ActiveCell.ColumnSpan}"
ActiveRowSpan="{Binding Path=Worksheet.ActiveCell.RowSpan}" SelectionColumn="{Binding Path=Worksheet.Selection.Column}"
SelectionRow="{Binding Path=Worksheet.Selection.Row}" SelectionRowSpan="{Binding Path=Worksheet.Selection.RowSpan}"
SelectionColumnSpan="{Binding Path=Worksheet.Selection.ColumnSpan}" Selection="{Binding Path=Worksheet.Selection}"
IsSelectionFullRow="{Binding Path=Worksheet.Selection.IsFullRow}"
IsSelectionFullColumn="{Binding Path=Worksheet.Selection.IsFullColumn}" />
      <ItemsControl Name="forTableBorders" ItemsSource="{Binding Worksheet.Tables}"
                    ItemTemplate="{StaticResource tableBorders}" ItemContainerStyle="{StaticResource tableBackgroundContainerStyle}">
        <ItemsControl.ItemsPanel>
          <ItemsPanelTemplate>
            <ssui:WorksheetGrid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Focusable="False"
                                x:Name="tableBordersPanel" Columns="{Binding Path=Worksheet.Columns}" Rows="{Binding Path=Worksheet.Rows}"
                                Top="{Binding Path=Top, Mode=TwoWay}" Left="{Binding Path=Left, Mode=TwoWay}" ClipToBounds="True" />
          </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>
      </ItemsControl>
      <Internals:CellBordersControl WorksheetPane="{Binding}" Focusable="False"
                                    ColorScheme="{Binding RelativeSource={RelativeSource Self}, Path=(drawing2:DrawingElement.ColorScheme)}" />
      <Internals:ClusteredCellTextControl WorksheetPane="{Binding}" Focusable="False" x:Name="ctc1"
                                          Tag="{Binding}" EditedCell="{Binding RelativeSource={RelativeSource Self}, Path=(Internals:EditionElement.EditedCell)}"
                                          ColorScheme="{Binding RelativeSource={RelativeSource Self}, Path=(drawing2:DrawingElement.ColorScheme)}" />
      <ssui:WorksheetGrid x:Name="EditingLayer" Focusable="True" Background="Transparent" Margin="0"
                          QueryCursor="OnQueryCursor" Tag="{Binding ElementName=editedCell}" Columns="{Binding Path=Worksheet.Columns}"
                          Rows="{Binding Path=Worksheet.Rows}" Top="{Binding Path=Top, Mode=TwoWay}" Left="{Binding Path=Left, Mode=TwoWay}"
                          FocusVisualStyle="{x:Null}">
        <ssui:WorksheetGrid.InputBindings>
          <KeyBinding Command="{x:Static ssui:SpreadsheetCommands.SelectRow}" Key="Space" Modifiers="Shift" />
          <KeyBinding Command="{x:Static ssui:SpreadsheetCommands.SelectColumn}" Key="Space"
                      Modifiers="Control" />
        </ssui:WorksheetGrid.InputBindings>
        <ContentControl Content="{Binding Path=Worksheet.Selection}" Loaded="OnContentLoaded"
                        Name="SelectionControl" Focusable="False" ssui:WorksheetGrid.Column="{Binding Path=Worksheet.Selection.Column}"
                        ssui:WorksheetGrid.Row="{Binding Path=Worksheet.Selection.Row}"
                        ssui:WorksheetGrid.RowSpan="{Binding Path=Worksheet.Selection.RowSpan}"
                        ssui:WorksheetGrid.ColumnSpan="{Binding Path=Worksheet.Selection.ColumnSpan}"
                        ssui:WorksheetGrid.IsFullRow="{Binding Path=Worksheet.Selection.IsFullRow}"
                        ssui:WorksheetGrid.IsFullColumn="{Binding Path=Worksheet.Selection.IsFullColumn}" />
        <ContentControl
Content="{Binding Path=(ssui:SpreadsheetElement.Highlight), RelativeSource={RelativeSource Self}}"
Name="highlightControl" ContentTemplate="{StaticResource highlight}"
ssui:WorksheetGrid.Column="{Binding Path=Content.Column, RelativeSource={RelativeSource Self}}"
ssui:WorksheetGrid.Row="{Binding Path=Content.Row, RelativeSource={RelativeSource Self}}"
ssui:WorksheetGrid.RowSpan="{Binding Path=Content.RowSpan, RelativeSource={RelativeSource Self}}"
ssui:WorksheetGrid.ColumnSpan="{Binding Path=Content.ColumnSpan, RelativeSource={RelativeSource Self}}"
ssui:WorksheetGrid.IsFullRow="{Binding Path=Content.IsFullRow, RelativeSource={RelativeSource Self}}"
ssui:WorksheetGrid.IsFullColumn="{Binding Path=Content.IsFullColumn, RelativeSource={RelativeSource Self}}">
          <ContentControl.Visibility>
            <MultiBinding Converter="{x:Static Internals:SpreadsheetConverters.MultiEqualConverter}">
              <Binding Path="(ssui:SpreadsheetElement.Highlight).Worksheet"
                       RelativeSource="{RelativeSource Self}" />
              <Binding Path="(ssui:SpreadsheetElement.Worksheet)" RelativeSource="{RelativeSource Self}" />
            </MultiBinding>
          </ContentControl.Visibility>

        </ContentControl>

        <ComboBox Name="validationCombo"
                  ssui:WorksheetGrid.Column="{Binding Worksheet.ActiveCell.Column.Index}"
                  ssui:WorksheetGrid.Row="{Binding Worksheet.ActiveCell.Row.Index}"
                  ssui:WorksheetGrid.ColumnSpan="{Binding Worksheet.ActiveCell.ColumnSpan}"
                  ssui:WorksheetGrid.RowSpan="{Binding Worksheet.ActiveCell.RowSpan}" HorizontalAlignment="Right" Cursor="Arrow"
                  Width="20" Margin="20 0 -20 0"
                  ItemsSource="{Binding RelativeSource={RelativeSource Self}, Path=(ssui:SpreadsheetElement.WorksheetViewModel).ValidationValues}"
                  SelectedItem="{Binding RelativeSource={RelativeSource Self}, Path=(ssui:SpreadsheetElement.WorksheetViewModel).SelectedValidationValue}">
        </ComboBox>
        <ContentControl
Content="{Binding RelativeSource={RelativeSource Self}, Path=(ssui:SpreadsheetElement.WorksheetViewModel).Formula.ActiveReference}"
Focusable="False" Name="EditedCellTarget" ContentTemplate="{StaticResource highlight}"
Visibility="{Binding RelativeSource={RelativeSource Self}, Path=Content, Converter={x:Static ssui:BooleanToVisibilityConverter.Instance}}"
ssui:WorksheetGrid.Column="{Binding RelativeSource={RelativeSource Self}, Path=(ssui:SpreadsheetElement.WorksheetViewModel).Formula.ActiveReference.Column}"
ssui:WorksheetGrid.Row="{Binding RelativeSource={RelativeSource Self}, Path=(ssui:SpreadsheetElement.WorksheetViewModel).Formula.ActiveReference.Row}"
ssui:WorksheetGrid.RowSpan="{Binding RelativeSource={RelativeSource Self}, Path=(ssui:SpreadsheetElement.WorksheetViewModel).Formula.ActiveReference.RowSpan}"
ssui:WorksheetGrid.ColumnSpan="{Binding RelativeSource={RelativeSource Self}, Path=(ssui:SpreadsheetElement.WorksheetViewModel).Formula.ActiveReference.ColumnSpan}"
ssui:WorksheetGrid.IsFullRow="{Binding RelativeSource={RelativeSource Self}, Path=(ssui:SpreadsheetElement.WorksheetViewModel).Formula.ActiveReference.IsFullRow}"
ssui:WorksheetGrid.IsFullColumn="{Binding RelativeSource={RelativeSource Self}, Path=(ssui:SpreadsheetElement.WorksheetViewModel).Formula.ActiveReference.IsFullColumn}" />
        <Rectangle
Tag="{Binding RelativeSource={RelativeSource Self}, Path=(ssui:SpreadsheetElement.DropTarget)}"
Visibility="{Binding RelativeSource={RelativeSource Self}, Path=Tag, Converter={x:Static ssui:BooleanToVisibilityConverter.Instance}}"
ssui:WorksheetGrid.Column="{Binding RelativeSource={RelativeSource Self}, Path=Tag.Column}"
ssui:WorksheetGrid.Row="{Binding RelativeSource={RelativeSource Self}, Path=Tag.Row}"
ssui:WorksheetGrid.RowSpan="{Binding RelativeSource={RelativeSource Self}, Path=Tag.RowSpan}"
ssui:WorksheetGrid.ColumnSpan="{Binding RelativeSource={RelativeSource Self}, Path=Tag.ColumnSpan}"
ssui:WorksheetGrid.IsFullRow="{Binding RelativeSource={RelativeSource Self}, Path=Tag.IsFullRow}"
ssui:WorksheetGrid.IsFullColumn="{Binding RelativeSource={RelativeSource Self}, Path=Tag.IsFullColumn}"
Style="{StaticResource dragRectangle}" />

        <ContentControl Name="autoFill"
                        Content="{Binding RelativeSource={RelativeSource Self}, Path=(ssui:SpreadsheetElement.AutoFill)}"
                        Tag="{Binding RelativeSource={RelativeSource Self}, Path=(ssui:SpreadsheetElement.AutoFill)}" Focusable="False"
                        ssui:WorksheetGrid.Column="{Binding RelativeSource={RelativeSource Self}, Path=Tag.Column}"
                        ssui:WorksheetGrid.Row="{Binding RelativeSource={RelativeSource Self}, Path=Tag.Row}"
                        ssui:WorksheetGrid.RowSpan="{Binding RelativeSource={RelativeSource Self}, Path=Tag.RowSpan}"
                        ssui:WorksheetGrid.ColumnSpan="{Binding RelativeSource={RelativeSource Self}, Path=Tag.ColumnSpan}"></ContentControl>
        <ContentControl
ssui:WorksheetGrid.Column="{Binding RelativeSource={RelativeSource Self}, Path=Content.Cell.Column.Index}"
ssui:WorksheetGrid.Row="{Binding RelativeSource={RelativeSource Self}, Path=Content.Cell.Row.Index}"
ssui:WorksheetGrid.RowSpan="{Binding RelativeSource={RelativeSource Self}, Path=Content.Cell.RowSpan}"
ssui:WorksheetGrid.ColumnSpan="{Binding RelativeSource={RelativeSource Self}, Path=Content.Cell.ColumnSpan}"
ssui:WorksheetGrid.Overflow="True"
ContentTemplateSelector="{Binding RelativeSource={RelativeSource Self}, Path=(ssui:SpreadsheetElement.CellEditorTemplateSelector)}"
Content="{Binding RelativeSource={RelativeSource Self}, Path=(Internals:EditionElement.EditedCell)}"
x:Name="editedCell" Focusable="True" />
      </ssui:WorksheetGrid>
      <ItemsControl Internals:FocusElement.NextFocusedElement="{Binding ElementName=EditingLayer}"
                    Name="CommentLayer" Focusable="False" Background="{x:Null}" ItemContainerStyle="{StaticResource commentContainerStyle}">
        <ItemsControl.ItemsSource>
          <MultiBinding
Converter="{x:Static Internals:SpreadsheetConverters.WorksheetPaneToCommentsConverter}">
            <Binding />
            <Binding Path="Worksheet.Generation" />
          </MultiBinding>
        </ItemsControl.ItemsSource>
        <ItemsControl.ItemsPanel>
          <ItemsPanelTemplate>
            <ssui:WorksheetGrid x:Name="commentsGrid" Background="{x:Null}"
                                Top="{Binding Path=Top, Mode=TwoWay}" Left="{Binding Path=Left, Mode=TwoWay}"
                                Columns="{Binding Path=Worksheet.Columns}" Rows="{Binding Path=Worksheet.Rows}" />
          </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>
        <ItemsControl.ItemTemplateSelector>
          <Internals:CommentTemplateSelector></Internals:CommentTemplateSelector>
        </ItemsControl.ItemTemplateSelector>
      </ItemsControl>
      <ItemsControl
ItemsSource="{Binding RelativeSource={RelativeSource Self}, Path=(ssui:SpreadsheetElement.WorksheetViewModel).Formula.References}"
x:Name="formulaReferences" Focusable="False" Background="{x:Null}"
ItemContainerStyle="{StaticResource formulaReferenceContainerStyle}" ClipToBounds="True">
        <ItemsControl.ItemsPanel>
          <ItemsPanelTemplate>
            <ssui:WorksheetGrid x:Name="referencesRangeswg2" Background="{x:Null}"
                                Top="{Binding Path=Top, Mode=TwoWay}" Left="{Binding Path=Left, Mode=TwoWay}"
                                Columns="{Binding Path=Worksheet.Columns}" Rows="{Binding Path=Worksheet.Rows}" />
          </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>
      </ItemsControl>

      <ItemsControl
ItemsSource="{Binding RelativeSource={RelativeSource Self}, Path=(ssui:SpreadsheetElement.WorksheetViewModel).References}"
x:Name="otherReferences" Focusable="False" Background="{x:Null}"
ItemContainerStyle="{StaticResource formulaReferenceContainerStyle}" ClipToBounds="True">
        <ItemsControl.ItemsPanel>
          <ItemsPanelTemplate>
            <ssui:WorksheetGrid x:Name="referencesRangeswg3" Background="{x:Null}"
                                Top="{Binding Path=Top, Mode=TwoWay}" Left="{Binding Path=Left, Mode=TwoWay}"
                                Columns="{Binding Path=Worksheet.Columns}" Rows="{Binding Path=Worksheet.Rows}" />
          </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>
      </ItemsControl>

      <ItemsControl ItemsSource="{Binding Worksheet.Tables}" Background="{x:Null}"
                    ItemTemplate="{StaticResource tableButtons}" />
      <ItemsControl
ItemsSource="{Binding Path=Worksheet.AutoFilter.FilterColumns, Converter={x:Static Internals:SpreadsheetConverters.FilterColumnViewModelsFactory}}"
Background="{x:Null}" ItemContainerStyle="{StaticResource filterColumnStyle}">
        <ItemsControl.ItemsPanel>
          <ItemsPanelTemplate>
            <ssui:WorksheetGrid x:Name="n2" Background="{x:Null}" Top="{Binding Path=Top, Mode=OneWay}"
                                Left="{Binding Path=Left, Mode=OneWay}" Columns="{Binding Path=Worksheet.Columns}" Rows="{Binding Path=Worksheet.Rows}" />
          </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>
      </ItemsControl>

      <AdornerDecorator>
        <ItemsControl ItemsSource="{Binding Worksheet.Anchors}" Focusable="False" x:Name="anchors"
                      Background="{x:Null}" Cursor="{x:Static Cursors.Arrow}" ItemContainerStyle="{StaticResource drawingContainerStyle}"
                      ClipToBounds="True" DataContext="{Binding}">
          <ItemsControl.CommandBindings>
            <CommandBinding Command="{x:Static ssui:SpreadsheetCommands.BringToFront}"
                            Executed="onBringToFront" />
            <CommandBinding Command="{x:Static ssui:SpreadsheetCommands.BringForward}"
                            Executed="onBringForward" />
            <CommandBinding Command="{x:Static ssui:SpreadsheetCommands.SendToBack}"
                            Executed="onSendToBack" />
            <CommandBinding Command="{x:Static ssui:SpreadsheetCommands.SendBackward}"
                            Executed="onSendBackward" />
          </ItemsControl.CommandBindings>
          <ItemsControl.ItemsPanel>
            <ItemsPanelTemplate>
              <ssui:WorksheetGrid x:Name="drawings" Cursor="{x:Static Cursors.Arrow}"
                                  Background="{x:Null}" Top="{Binding Path=Top, Mode=TwoWay}" Left="{Binding Path=Left, Mode=TwoWay}"
                                  Columns="{Binding Path=Worksheet.Columns}" Rows="{Binding Path=Worksheet.Rows}" />

            </ItemsPanelTemplate>
          </ItemsControl.ItemsPanel>
        </ItemsControl>
      </AdornerDecorator>
    </Grid>
    <DataTemplate.Triggers>
      <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=(Internals:EditionElement.EditedCell)}"
                   Value="{x:Null}">
        <Setter Property="Visibility" TargetName="editedCell" Value="Hidden" />
      </DataTrigger>
      <DataTrigger
Binding="{Binding RelativeSource={RelativeSource Self}, Path=(ssui:SpreadsheetElement.WorksheetViewModel).ValidationValues}"
Value="{x:Null}">
        <Setter Property="Visibility" TargetName="validationCombo" Value="Hidden"></Setter>
      </DataTrigger>
    </DataTemplate.Triggers>
  </DataTemplate>


</ResourceDictionary>